//
//  DDelicateOfCartoonViewController.m
//  ABookOfCartoon
//
//  Created by 美国大狗 on 15-5-19.
//  Copyright (c) 2015年 Power Of Ants. All rights reserved.
//

#import "DDelicateOfCartoonViewController.h"
#import "UIImageView+WebCache.h"
#import "JCReadViewController.h"
#import "JCDataCollectManager.h"

@interface DDelicateOfCartoonViewController ()<UIScrollViewAccessibilityDelegate, UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UIImageView *cartoonImage;
@property (nonatomic, retain)UILabel *cartoonName;
@property (nonatomic, retain)UILabel *author;
@property (nonatomic, retain)UILabel *love;
@property (nonatomic, retain)UILabel *over;
@property (nonatomic, retain)UILabel *delicate;
@property (nonatomic, retain)UITableView *lineOfWeb;
@property (nonatomic, retain)UILabel *web;
@property (nonatomic, retain)UIButton *jumpButton;

@property (nonatomic, retain)UIButton *button1;
@end

@implementation DDelicateOfCartoonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"漫画详情";
    NSLog(@"详情页面准备就绪!");
    [self createScrollView];
}
- (void)createScrollView
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height  - 44)];
    scrollView.contentSize = CGSizeMake(0, 1000);
    scrollView.tag = 1001;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    [scrollView release];

    self.cartoonImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, self.view.bounds.size.width / 3, self.view.bounds.size.width / 3 + 50)];
    [_cartoonImage sd_setImageWithURL:[NSURL URLWithString:[_BookDic objectForKey:@"BookIconOtherURL"]]];
    [scrollView addSubview:_cartoonImage];
    [_cartoonImage release];
    
    self.cartoonName = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3 + 30, 20, self.view.bounds.size.width / 2, ((self.view.bounds.size.width / 3 + 50) / 4))];
    //    _cartoonName.text = [_dataArr[0] objectForKey:@"BookName"];
    NSString *cN = [_BookDic objectForKey:@"BookName"];
    NSString *MB = [NSString stringWithFormat:@"书名 %@", cN];
    _cartoonName.text = MB;
    [scrollView addSubview:_cartoonName];
    [_cartoonName release];
    
    self.author = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3 + 30, 20 + (self.view.bounds.size.width / 3 + 50) / 4  , self.view.bounds.size.width / 2, ((self.view.bounds.size.width / 3 + 50) / 4))];
    //    _author.text = [_dataArr[0] objectForKey:@"BookAuthor"];
    _author.text = [NSString stringWithFormat:@"作者 %@", [_BookDic objectForKey:@"BookAuthor"]];
    [scrollView addSubview:_author];
    [_author release];
    
    self.love = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3 + 30, 20 + (self.view.bounds.size.width / 3 + 50) / 2, self.view.bounds.size.width / 2, ((self.view.bounds.size.width / 3 + 50) / 4))];
    //    _author.text = [_dataArr[0] objectForKey:@"BookAuthor"];
    _love.text = [NSString stringWithFormat:@"人气 %@", [_BookDic objectForKey:@"BookClickCount"]];
    [scrollView addSubview:_love];
    [_love release];
    
    self.over = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3 + 30, 20 + (self.view.bounds.size.width / 3 + 50) - (self.view.bounds.size.width / 3 + 50) / 4, self.view.bounds.size.width / 2, (self.view.bounds.size.width / 3 + 50) / 4)];
    _over.text = [NSString stringWithFormat:@"状态 %@", [_BookDic objectForKey:@"BookStateName"]];
    [scrollView addSubview:_over];
    [_over release];
    
    self.delicate = [[UILabel alloc] initWithFrame:CGRectMake(20, 30 + (self.view.bounds.size.width / 3 + 50) + (self.view.bounds.size.width / 3 + 50) / 4, self.view.bounds.size.width - 40, 300)];
    //    _delicate.backgroundColor = [UIColor blackColor];
    _delicate.text = [_BookDic objectForKey:@"BookDescription"];
    _delicate.numberOfLines = 0;
    [_delicate sizeToFit];
    [scrollView addSubview:_delicate];
    [_delicate release];
    
    self.jumpButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _jumpButton.frame = CGRectMake(self.view.frame.size.width / 3, (self.view.bounds.size.width / 3 + 50) + (self.view.bounds.size.width / 3 + 50) / 4 + _delicate.frame.size.height + 70, self.view.frame.size.width / 3, 40);
    [_jumpButton setTitle:@"开始阅读" forState:UIControlStateNormal];
    [_jumpButton addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside];
    [_jumpButton.layer setCornerRadius:5];
    [_jumpButton.layer setBorderWidth:1];
    [scrollView addSubview:_jumpButton];

    self.button1 = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 3,  (self.view.bounds.size.width / 3 + 50) + (self.view.bounds.size.width / 3 + 50) / 4 + _delicate.frame.size.height + 70 + _jumpButton.frame.size.height, self.view.frame.size.width / 3, 40)];
    //    _button1.backgroundColor = [UIColor redColor];
    [_button1 setTitle:@"收藏" forState:UIControlStateNormal];
    [_button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [_button1 addTarget:self action:@selector(but1) forControlEvents:UIControlEventTouchUpInside];
    [_button1.layer setCornerRadius:5];
    [_button1.layer setBorderWidth:1];
    [scrollView addSubview:_button1];
    
    scrollView.contentSize = CGSizeMake(0, 260 + (self.view.bounds.size.width / 3 + 50) + (self.view.bounds.size.width / 3 + 50) / 4 + _delicate.frame.size.height);
}

-(void)but1
{
    [_button1 setTitle:@"已收藏" forState:UIControlStateNormal];
//    _button1.tag = 1001;
    JCDataCollectManager *dbManager = [JCDataCollectManager shareInstance];
    [dbManager openDB];
    [dbManager createTable];
    JCMainPageModel *name = [[JCMainPageModel alloc]init];
    name.BookName = _cartoonName.text;
    //name.BookAuthor = h.BookAuthor;
    [dbManager insertInfowithJCMainPageModel:name];
    [name release];
}

- (void)jump
{
    NSLog(@"跳转!");
    JCReadViewController *sb = [[JCReadViewController alloc] init];
    sb.str7 = [_BookDic objectForKey:@"BookID"];
    [self.navigationController pushViewController:sb animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
